package com.zx.lc.service;

import com.zx.lc.model.AiModel;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.ollama.OllamaChatModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.springframework.stereotype.Service;

@Service
public class ChatAiModelService {

    private static List<AiModel> AI_MODELS = new ArrayList<>();

    private static AiModel DEFAULT_MODEL;

    static {
        AI_MODELS.add(new AiModel("qwen2.5:0.5b", "ollama",
                OllamaChatModel.builder()
                        .baseUrl("http://192.168.3.99:11434")
                        .modelName("qwen2.5:0.5b")
                        .build()));

        AI_MODELS.add(new AiModel("qwen2.5:7b", "ollama", OllamaChatModel.builder()
                .baseUrl("http://192.168.3.99:11434")
                .modelName("qwen2.5:7b")
                .build()));

        AI_MODELS.add(new AiModel("deepseek-r1:7b", "ollama", OllamaChatModel.builder()
                .baseUrl("http://192.168.3.99:11434")
                .modelName("deepseek-r1:7b")
                .build()));

        DEFAULT_MODEL = AI_MODELS.get(1);
    }

    public static List<AiModel> getAiModels() {
        return AI_MODELS;
    }

    public static ChatLanguageModel getAiModel(String modelName) {
        return (ChatLanguageModel) AI_MODELS.stream()
                .filter(am -> Objects.equals(modelName, am.getName()))
                .findAny()
                .orElseGet(() -> DEFAULT_MODEL).getAiModel();
    }
}
